package com.ns.basic.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ns.basic.server.dto.ServerPageDto;
import com.ns.basic.server.entry.ServerEntry;
import com.ns.basic.server.mapper.ServerEntryMapper;
import com.ns.basic.server.vo.ServerEntryVO;
import com.ns.core.vo.login.ServObjVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务模块业务实现接口
 *
 * @author lw
 */
@Service
@RequiredArgsConstructor
public class ServerServiceImpl extends ServiceImpl<ServerEntryMapper, ServerEntry> implements IServerService {

    private final ServerEntryMapper serverEntryMapper;

    @Override
    public Page<ServerEntryVO> selectBy(ServerPageDto dto) {
        return serverEntryMapper.selectBy(dto, new Page<>(dto.getCurrent(), dto.getSize()));
    }

    @Override
    public Map<Long, String> selectServer() {
        List<ServerEntry> servers = serverEntryMapper.selectList(new QueryWrapper<>());
        Map<Long, String> jsd = new HashMap<>();
        if (!CollectionUtils.isEmpty(servers)) {
            for (ServerEntry server : servers) {
                jsd.put(server.getId(), server.getName());
            }
        }
        return jsd;
    }

    @Override
    public ServObjVO getByCode(String code) {
        return serverEntryMapper.getByCode(code);
    }
}
